package org.sgr.money.manager.frame;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;

public class MmgrFrame1 {

	private Shell sShell = null;
	private Menu menuBar = null;
	private Menu submenu = null;
	private Menu submenu1 = null;
	private Menu submenu2 = null;
	private Menu submenu3 = null;
	private Menu submenu4 = null;
	private CTabFolder cTabFolder = null;
	private TabFolder tabFolder1 = null;

	/**
	 * This method initializes sShell
	 */
	@SuppressWarnings("unused")
	private void createSShell() {
		sShell = new Shell(SWT.SHELL_TRIM);
		sShell.setText("money manager");
		sShell.setLayout(new FormLayout());
		createCTabFolder();
		sShell.setSize(new Point(600, 400));
		menuBar = new Menu(sShell, SWT.BAR);
		MenuItem submenuItem1 = new MenuItem(menuBar, SWT.CASCADE);
		submenuItem1.setText("我的账户");
		MenuItem submenuItem = new MenuItem(menuBar, SWT.CASCADE);
		submenuItem.setText("记账");
		MenuItem submenuItem2 = new MenuItem(menuBar, SWT.CASCADE);
		submenuItem2.setText("查询统计");
		MenuItem submenuItem3 = new MenuItem(menuBar, SWT.CASCADE);
		submenuItem3.setText("基本资料");
		MenuItem submenuItem4 = new MenuItem(menuBar, SWT.CASCADE);
		submenuItem4.setText("帮助");
		submenu4 = new Menu(submenuItem4);
		submenuItem4.setMenu(submenu4);
		submenu3 = new Menu(submenuItem3);
		submenuItem3.setMenu(submenu3);
		submenu2 = new Menu(submenuItem2);
		submenuItem2.setMenu(submenu2);
		submenu1 = new Menu(submenuItem1);
		MenuItem push = new MenuItem(submenu1, SWT.PUSH);
		push.setText("概况");

		push.addDisposeListener(new org.eclipse.swt.events.DisposeListener() {
			public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
				System.out.println("widgetDisposed()");
			}
		});
		MenuItem separator = new MenuItem(submenu1, SWT.SEPARATOR);
		MenuItem push1 = new MenuItem(submenu1, SWT.PUSH);
		push1.setText("资金状况");
		MenuItem push2 = new MenuItem(submenu1, SWT.PUSH);
		push2.setText("现金");
		push2.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
				System.out.println("现金 widgetSelected()");
				createCashComp();
			}

			public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
			}
		});
		MenuItem push3 = new MenuItem(submenu1, SWT.PUSH);
		push3.setText("银行");
		MenuItem push4 = new MenuItem(submenu1, SWT.PUSH);
		push4.setText("应收");
		MenuItem push5 = new MenuItem(submenu1, SWT.PUSH);
		push5.setText("应付");
		MenuItem separator1 = new MenuItem(submenu1, SWT.SEPARATOR);
		MenuItem push6 = new MenuItem(submenu1, SWT.PUSH);
		push6.setText("定期");
		MenuItem push7 = new MenuItem(submenu1, SWT.PUSH);
		push7.setText("信用卡");
		submenuItem1.setMenu(submenu1);
		submenu = new Menu(submenuItem);
		submenuItem.setMenu(submenu);
		sShell.setMenuBar(menuBar);
	}

	/**
	 * This method initializes cTabFolder
	 * 
	 */
	private void createCTabFolder() {
		cTabFolder = new CTabFolder(sShell, SWT.BORDER);
		// cTabFolder.set
		FormData data = new FormData();
		data.top = new FormAttachment(0, 0);
		data.left = new FormAttachment(0, 0);
		data.bottom = new FormAttachment(100, 0);
		data.right = new FormAttachment(100, 0);
		cTabFolder.setLayoutData(data);
		createTabFolder1();
	}

	private void createCashComp() {
		boolean flag = false;
		for (CTabItem cTabItem : cTabFolder.getItems()) {
			if ("现金".equals(cTabItem.getText())) {
				cTabFolder.setSelection(cTabItem);
				flag = true;
				break;
			}
		}
		if (!flag) {
			createCashCompTabItem();
		}
	}

	private void createCashCompTabItem() {
		TabFolder tabFolder = new TabFolder(cTabFolder, SWT.NONE);
		tabFolder.setLayout(new FillLayout());
		CTabItem cTabItem = new CTabItem(cTabFolder, SWT.CLOSE);
		cTabItem.setControl(tabFolder);
		cTabItem.setText("现金");
		new CashComp(tabFolder, cTabItem.getStyle());
		cTabFolder.setSelection(cTabItem);
	}

	/**
	 * This method initializes tabFolder1
	 * 
	 */
	private void createTabFolder1() {
		tabFolder1 = new TabFolder(cTabFolder, SWT.NONE);
		CTabItem cTabItem1 = new CTabItem(cTabFolder, SWT.NONE);
		cTabItem1.setControl(tabFolder1);
		cTabItem1.setText("欢迎");
	}
}
